# 导包
import requests
import app,utils
import unittest

# 创建类
from api.reg_API import REG_API


class TestLOGIN02(unittest.TestCase):
    #      前置处理
    def setUp(self) -> None:
        # 实例化封装类
        self.LOGINAPI = REG_API()
        # 实例化session
        self.session = requests.session()

    #        后置处理
    def tearDown(self) -> None:
        # 关闭session
        self.session.close()

    #          登录成功
    def test01_success_login(self):
        response = self.LOGINAPI.post_login(self.session, {"keywords": "18912340001", "password": "test123"})
        print(response.json())
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(200, response.json().get("status"))
        # self.assertIn("登录成功", response.text)
        utils.common_assert(self,response,200,200,"登录成功")
    # 账号不存在
    def test02_username_is_not(self):
        response = self.LOGINAPI.post_login(self.session, {"keywords": "18912340043", "password": "test123"})
        print(response.json())
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(100, response.json().get("status"))
        # self.assertIn("用户不存在", response.text)
        utils.common_assert(self,response,200,100,"用户不存在")
    # 密码为空
    def test03_password_is_not(self):
        response = self.LOGINAPI.post_login(self.session, {"keywords": "18912340043", "password": ""})
        print(response.json())
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(100, response.json().get("status"))
        # self.assertIn("密码不能为空", response.text)
        utils.common_assert(self,response,200,100,"密码不能为空")